<?php
namespace app\run\model;
use think\Db;
use think\Model;

class Store extends Model
{
	/*
	* 单条数据查询
	* @param string $name
	* @return int 
	*/ 
	public static function find($where){
		$res = Db::name('store_city')->where($where)->find();
		return $res;
	}

	/*
	* 城市添加
	* @param string $name
	* @return int 
	*/ 
	public static function cityAdd($name){
		$res = Db::name('store_city')->insert($name);
		return $res;
	}

	/*
	* 城市查询
	* @param array $options
	* @return array $res
	*/ 
	public static function cityIndex($options){
		$res = Db::name('store_city')->field('id,name')->paginate(5,false,$options);
		return $res;
	}

	/*
	* 城市修改
	* @param array $data
	* @return int $res
	*/ 
	public static function cityUpdate(array $data){
		$res = Db::name('store_city')->update($data);
		return $res;
	}

	/*
	* 城市查询
	* @return array $res
	*/ 
	public static function cityCat(){
		$res = Db::name('store_city')->field('id,name')->select();
		return $res;
	}

	/*
	* 门店添加
	* @param array $data
	* @return int $res
	*/ 
	public static function infoInsert(array $data){
		$res = Db::name('store_info')->insert($data);
		return $res;
	}

	/*
	* 门店添加
	* @return array $res
	*/ 
	public static function index($options){
		// $data = array();
		$res = Db::name('store_info')->alias('a')
		->join('store_city b','a.city_id=b.id')
		->field('a.id,a.address,a.phone,a.city_id,a.company,b.name')
		->paginate(5,false,$options);
	
		return $res;
	}



	/*
	* 门店修改默认数据查询
	* @return array $data
	*/ 
	public static function findInfo($id){
		// $data = array();
		$res = Db::name('store_info')->alias('a')
		->join('store_city b','a.city_id=b.id')
		->where('a.id',$id)
		->find();
		
		return $res;
	}

	/*
	* 门店数据修改
	* @param array $data
	* @return int $res
	*/ 
	public static function infoUpdate($data){
		// $data = array();
		$res = Db::name('store_info')->update($data);
		
		return $res;
	}

	/*
	* 门店数据删除
	* @param int $id
	* @return int $res
	*/ 
	public static function infoDel($id){
		// $data = array();
		$res = Db::name('store_info')->where('id',$id)->delete();
		
		return $res;
	}
}